package paquete.prueba.escribir;

/**
 * @(#)intentoescribir.java
 *
 *
 * @author
 * @version 1.00 2013/5/8
 */
import static org.semanticweb.owlapi.vocab.OWLFacet.*;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat;
import org.coode.owlapi.turtle.TurtleOntologyFormat;
//import org.junit.Ignore;
//import org.junit.Test;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.OWLOntologyDocumentTarget;
import org.semanticweb.owlapi.io.OWLXMLOntologyFormat;
import org.semanticweb.owlapi.io.RDFXMLOntologyFormat;
import org.semanticweb.owlapi.io.StreamDocumentTarget;
import org.semanticweb.owlapi.io.StringDocumentTarget;
import org.semanticweb.owlapi.io.SystemOutDocumentTarget;
import org.semanticweb.owlapi.model.AddAxiom;
import org.semanticweb.owlapi.model.AddOntologyAnnotation;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDataExactCardinality;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom;
import org.semanticweb.owlapi.model.OWLDataRange;
import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom;
import org.semanticweb.owlapi.model.OWLDataUnionOf;
import org.semanticweb.owlapi.model.OWLDatatype;
import org.semanticweb.owlapi.model.OWLDatatypeDefinitionAxiom;
import org.semanticweb.owlapi.model.OWLDatatypeRestriction;
import org.semanticweb.owlapi.model.OWLDeclarationAxiom;
import org.semanticweb.owlapi.model.OWLDifferentIndividualsAxiom;
import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom;
import org.semanticweb.owlapi.model.OWLFacetRestriction;
import org.semanticweb.owlapi.model.OWLFunctionalDataPropertyAxiom;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLLiteral;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom;
import org.semanticweb.owlapi.model.OWLObjectExactCardinality;
import org.semanticweb.owlapi.model.OWLObjectHasValue;
import org.semanticweb.owlapi.model.OWLObjectIntersectionOf;
import org.semanticweb.owlapi.model.OWLObjectOneOf;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyFormat;
import org.semanticweb.owlapi.model.OWLOntologyID;
import org.semanticweb.owlapi.model.OWLOntologyIRIMapper;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;
import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom;
import org.semanticweb.owlapi.model.PrefixManager;
import org.semanticweb.owlapi.model.SWRLAtom;
import org.semanticweb.owlapi.model.SWRLObjectPropertyAtom;
import org.semanticweb.owlapi.model.SWRLRule;
import org.semanticweb.owlapi.model.SWRLVariable;
import org.semanticweb.owlapi.model.SetOntologyID;
import org.semanticweb.owlapi.reasoner.BufferingMode;
import org.semanticweb.owlapi.reasoner.ConsoleProgressMonitor;
import org.semanticweb.owlapi.reasoner.InferenceType;
import org.semanticweb.owlapi.reasoner.Node;
import org.semanticweb.owlapi.reasoner.NodeSet;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import org.semanticweb.owlapi.reasoner.SimpleConfiguration;
import org.semanticweb.owlapi.reasoner.structural.StructuralReasoner;
import org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory;
import org.semanticweb.owlapi.util.AutoIRIMapper;
import org.semanticweb.owlapi.util.DefaultPrefixManager;
import org.semanticweb.owlapi.util.InferredAxiomGenerator;
import org.semanticweb.owlapi.util.InferredOntologyGenerator;
import org.semanticweb.owlapi.util.InferredSubClassAxiomGenerator;
import org.semanticweb.owlapi.util.OWLClassExpressionVisitorAdapter;
import org.semanticweb.owlapi.util.OWLEntityRemover;
import org.semanticweb.owlapi.util.OWLOntologyMerger;
import org.semanticweb.owlapi.util.OWLOntologyWalker;
import org.semanticweb.owlapi.util.OWLOntologyWalkerVisitor;
import org.semanticweb.owlapi.util.SimpleIRIMapper;
import org.semanticweb.owlapi.vocab.OWL2Datatype;
import org.semanticweb.owlapi.vocab.OWLFacet;
import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;

import uk.ac.manchester.cs.owlapi.modularity.ModuleType;
import uk.ac.manchester.cs.owlapi.modularity.SyntacticLocalityModuleExtractor;

public class EscribiendoOntoNubeFormacion {

    private static final String PIZZA_IRI = "http://www.co-ode.org/ontologies/pizza/pizza.owl";

    /**
     * The following example uses entities and axioms that are used in the OWL
     * Primer. The purpose of this example is to illustrate some of the methods
     * of creating class expressions and various types of axioms. Typically, an
     * ontology wouldn't be constructed programmatically in a long drawn out
     * fashion like this, it would be constructe in an ontology editor such as
     * Protege 4, or Swoop. The OWL API would then be used to examine the
     * asserted structure of the ontology, and in conjunction with an OWL
     * reasoner such as FaCT++ or Pellet used to query the inferred ontology.
     *
     * @throws OWLOntologyCreationException
     * @throws OWLOntologyStorageException
     */
//    @Test
    public void hacerOntologia() throws OWLOntologyCreationException,
            OWLOntologyStorageException {
        // The OWLOntologyManager is at the heart of the OWL API, we can create
        // an instance of this using the OWLManager class, which will set up
        // commonly used options (such as which parsers are registered etc.
        // etc.)
        //OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        // We want to create an ontology that corresponds to the ontology used
        // in the OWL Primer. Every ontology has a URI that uniquely identifies
        // the ontology. The URI is essentially a name for the ontology. Note
        // that the URI doesn't necessarily point to a location on the web - in
        // this example, we won't publish the ontology at the URL corresponding
        // to the ontology URI below.
        
        //*************************************************Probar con esto
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
           // System.out.println("IRImia: "+pathOwl);
            File file = new File("C://OntoDominio.owl");
            OWLOntology ont = manager.loadOntologyFromOntologyDocument(file);
            //ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
            //OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
            OWLDataFactory fac = manager.getOWLDataFactory();
            IRI ontologyIRI = manager.getOntologyDocumentIRI(ont);
//            OWLIndividual OA = fac.getOWLNamedIndividual(IRI.create("#" + titulo));
        
     //----------------------------------------------------------------------------------------------   
       // IRI ontologyIRI = IRI.create("http://www.semanticweb.org/usuario/ontologies/2013/3/ontologiadedominio#");
        // Now that we have a URI for out ontology, we can create the actual
        // ontology. Note that the create ontology method throws an
        // OWLOntologyCreationException if there was a problem creating the
        // ontology.
       // OWLOntology ont = manager.createOntology(ontologyIRI);
        // We can use the manager to get a reference to an OWLDataFactory. The
        // data factory provides a point for creating OWL API objects such as
        // classes, properties and individuals.
        OWLDataFactory factory = manager.getOWLDataFactory();
        // We first need to create some references to individuals. All of our
        // individual must have URIs. A common convention is to take the URI of
        // an ontology, append a # and then a local name. For example we can
        // create the individual 'John', using the ontology URI and appending
        // #John. Note however, that there is no reuqirement that a URI of a
        // class, property or individual that is used in an ontology have a
        // correspondance with the URI of the ontology.

        OWLClass Estudiante = factory.getOWLClass(IRI.create(ontologyIRI + "#Estudiante"));
        OWLClass Profesor = factory.getOWLClass(IRI.create(ontologyIRI + "#Profesor"));
        OWLClass Modulo = factory.getOWLClass(IRI.create(ontologyIRI + "#Modulo"));

        OWLObjectProperty tieneModulo = factory.getOWLObjectProperty(IRI.create(ontologyIRI
                + "#tieneModulo"));

        OWLIndividual john = factory.getOWLNamedIndividual(IRI.create(ontologyIRI +
 "#John"));
        
        OWLClassAssertionAxiom classAssertionAx = factory.getOWLClassAssertionAxiom(
                Estudiante, john);
        
manager.addAxiom(ont, classAssertionAx);
        
        OWLIndividual IntelingenciaArtificial = factory.getOWLNamedIndividual(IRI.create(ontologyIRI +
 "#Algebra_Lineal"));


        OWLObjectPropertyAssertionAxiom axiom1 = factory
                .getOWLObjectPropertyAssertionAxiom(tieneModulo, john, IntelingenciaArtificial);

        AddAxiom addAxiom1 = new AddAxiom(ont, axiom1);

        manager.applyChange(addAxiom1);

        // Ontology Management //Having added axioms to out ontology we can now
        // save it (in a variety of formats). RDF/XML is the default format
  /*      System.out.println("RDF/XML: ");
         manager.saveOntology(ont, new StreamDocumentTarget(System.out));
         // OWL/XML */
//        System.out.println("OWL/XML: ");
//        File file1 = new File("C://OntoDominio.owl");
        manager.saveOntology(ont, IRI.create(file));
        
//        manager.saveOntology(ont, new OWLXMLOntologyFormat(), new StreamDocumentTarget(
//                System.out));
        // Manchester Syntax
    /*    System.out.println("Manchester syntax: ");
         manager.saveOntology(ont, new ManchesterOWLSyntaxOntologyFormat(),
         new StreamDocumentTarget(System.out));
         // Turtle
         System.out.println("Turtle: ");
         manager.saveOntology(ont, new TurtleOntologyFormat(), new StreamDocumentTarget(
         System.out));*/
    }

    public static void main(String[] arg) throws Exception {
        EscribiendoOntoNubeFormacion obj = new EscribiendoOntoNubeFormacion();
        obj.hacerOntologia();
    }
}